#ifndef PLAYERCONTROLS_H
#define PLAYERCONTROLS_H

#include <QMediaPlayer>
#include <QWidget>

class PlayerControls : public QWidget
{
    Q_OBJECT

public:
    PlayerControls(QWidget *parent = 0);
    Q_INVOKABLE qint64 getDuration();
    Q_INVOKABLE QMediaPlayer::State state() const;
    Q_INVOKABLE bool isPlay() const;
    Q_INVOKABLE int volume() const;
    Q_INVOKABLE bool isMuted() const;
    Q_INVOKABLE qreal playbackRate() const;
    void setPlayer(QMediaPlayer *player);
public slots:

    void setState(QMediaPlayer::State state);
    void setVolume(int volume);
    void setMuted(bool muted);
    void setPlaybackRate(float rate);
    void playClicked();
    void muteClicked();

    void durationChanged(qint64 duration);
    void positionChanged(qint64 progress);

    void seek(int seconds);

signals:
    void play();
    void pause();
    void stop();
    void next();
    void previous();
    void stateChanged();
    void changeVolume(int volume);
    void changeMuting(bool muting);
    void changeRate(qreal rate);
    void changeDurationInfo(QString tStr);
    void changeDurationLabel(qint64 count);
    void changePositionLabel(qreal count);
private:
    void updateDurationInfo(qint64 currentInfo);

    QMediaPlayer::State playerState;
    bool playerMuted;
    int m_volume;
    float m_rate;
    qint64 m_duration;
    qint64 m_progress;
    QMediaPlayer *m_player;
};
#endif // PLAYERCONTROLS_H
